package com.naza.rpc.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

    private static Object LOCK = new Object();

    public static PropertiesUtil INSTANCE;

    private static Properties properties = new Properties();

    public static PropertiesUtil getINSTANCE(){
        synchronized (LOCK){
            if(null == INSTANCE){
                synchronized (LOCK){
                    if(null == INSTANCE){
                        INSTANCE = new PropertiesUtil();
                        init();
                    }
                }
            }
        }
        return INSTANCE;
    }

    private static void init(){
        InputStream serverStream = PropertiesUtil.class.getClassLoader().getResourceAsStream("server.properties");
        InputStream clientStream = PropertiesUtil.class.getClassLoader().getResourceAsStream("client.properties");

        try {
            if(null != serverStream){
                properties.load(serverStream);
            }
            if(null != clientStream){
                properties.load(clientStream);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String getValue(String key){
        return properties.getProperty(key);
    }
}
